<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>利润报表</title>
	<include file="Public:header" />
	<style type="text/css">
		.input{width:100px;border:1px solid #ccc;padding:2px;}
	</style>
	<script type="text/javascript">
		var actflg="{:C('URL_MODEL')}"=="0"?"&":"?";

		function selectall_todo()
		{
			$("input[name='chk_list']").attr("checked",true);
		}
		function selectall_undo()
		{
			$("input[name='chk_list']").attr("checked",false);
		}
        function profit_todo_print()
		{
			$("input[id='frm_001_mas_fadate1']").attr("value",$("input[id='mas_fadate1']").val());
            $("input[id='frm_001_mas_fadate2']").attr("value",$("input[id='mas_fadate2']").val());
            $("input[id='frm_001_acc_title']").attr("value",$("input[id='acc_title']").val());
            $("input[id='frm_001_act_flg']").attr("value",$("input[id='act_flg']").val());
            $('#frm_001').submit();
		}
        function open_detail(acc_title)
		{
			var dt1=$("input[id='mas_fadate1']").val();
            var dt2=$("input[id='mas_fadate2']").val();
            parent.addTab("销售明细("+acc_title+")","{:U('Sales/profit_report_detail')}"+actflg+"mas_fadate1="+dt1+"&mas_fadate2="+dt2+"&acc_title="+acc_title+"");
		}
		$(document).ready(function(){
			$('#misone_list_table').datagrid({
				//url: '///',
				//title: 'DataGrid',
				//width: 800,
				//height: 220,
				fitColumns: true,
				nowrap:true,
				rownumbers:true,
				showFooter:false,
				columns:[[
					{field:'col01',title:'客户',width:200},
					{field:'col02',title:'销售金额',width:80},
					{field:'col03',title:'退货金额',width:80},
					{field:'col04',title:'小计金额',width:80},
					{field:'col05',title:'成本金额',width:80},
					{field:'col06',title:'毛利',width:80},
					{field:'col07',title:'毛利率',width:80}
				]]
			});
		});
	</script>
</head>
<body class="">
	<div class="demo-info space-out-5px">
		<div class="demo-tip icon-tip"></div>
		<div>利润报表</div>
		<div>
		<form id="frm_search" method="post" action="{:U('Sales/profit_report')}" style="margin:10px auto 0px 25px;">
		
		<div style="width:100%; height:25px;">
		
		<div class="list-t-l w60px">日期(从)：</div>
		<div class="list-t-l w120px"><input type="text" id="mas_fadate1" name="mas_fadate1" class="easyui-datebox"  editable="false" value="{$mas_fadate1}" style="width:100px;" /></div>
		
        <div class="list-t-l w60px">日期(到)：</div>
		<div class="list-t-l w120px"><input type="text" id="mas_fadate2" name="mas_fadate2" class="easyui-datebox"  editable="false" value="{$mas_fadate2}" style="width:100px;" /></div>
		
		<div class="list-t-l w60px">客户：</div>
		<div class="list-t-l w120px"><input type="text" id="acc_title" name="acc_title" class="input" value="{$acc_title}" /></div>
		
		<div class="list-t-l">
            <a href="javascript:;" class="easyui-linkbutton" iconCls="icon-search" onclick="$('#frm_search').submit();">统计</a>
            <a href="javascript:;" class="easyui-linkbutton" iconCls="icon-print" onclick="profit_todo_print();">打印</a>            
        </div>
		
		</div>
		
		<div style="height:3px; clear:both;"></div>
		
		
		</form>
        <form id="frm_001" method="post" target="_blank" action="{:U('Sales/profit_report_export')}" style="margin:0px;">
            <input type="hidden" id="frm_001_mas_fadate1" name="mas_fadate1" />
            <input type="hidden" id="frm_001_mas_fadate2" name="mas_fadate2" />
            <input type="hidden" id="frm_001_acc_title" name="acc_title" />
            <input type="hidden" id="frm_001_act_flg" name="act_flg" value="print" />
        </form>
        
		</div>
	</div>
	<div class="list-box space-out-5px">
	
	<table id="misone_list_table"><tbody>
    <php>$total_amount1=0;$total_amount2=0;$total_amount3=0;$total_cost=0;$total_profit=0;</php>
	<volist name="datalist" id="datalist">
	<tr>		
		<td field="col01"><a href="javascript:;" onclick="open_detail('{$datalist.acc_title}');">{$datalist.acc_title}</a></td>
		<td field="col02">{$datalist.amount1|get_round=###,2}<php>$total_amount1+=(double)$datalist['amount1'];</php></td>
		<td field="col03">{$datalist.amount2|get_round=###,2}<php>$total_amount2+=(double)$datalist['amount2'];</php></td>
		<td field="col04"><php>$amount3 = get_round((double)$datalist['amount1']-(double)$datalist['amount2'],2);echo $amount3;$total_amount3+=(double)$amount3;</php></td>
		<td field="col05">{$datalist.cost|get_round=###,2}<php>$total_cost+=(double)$datalist['cost'];</php></td>
		<td field="col06"><php>$profit = get_round((double)$amount3 - (double)$datalist['cost'],2);echo $profit;$total_profit+=(double)$profit;</php></td>
		<td field="col07"><php>echo get_round((double)$profit/(double)$amount3*100,2);</php>%</td>
	</tr>
	</volist>
    
    <tr>		
		<td field="col01">总计：</td>
		<td field="col02"><php>echo get_round($total_amount1,2);</php></td>
		<td field="col03"><php>echo get_round($total_amount2,2);</php></td>
		<td field="col04"><php>echo get_round($total_amount3,2);</php></td>
		<td field="col05"><php>echo get_round($total_cost,2);</php></td>
		<td field="col06"><php>echo get_round($total_profit,2);</php></td>
		<td field="col07"><php>echo get_round((double)$total_profit/(double)$total_amount3*100,2);</php>%</td>
	</tr>
    
	</tbody></table>
	
	<div style="height:5px; clear:both;"></div>
	
	</div>
	

</body>
</html>
